<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript异步编程</title>
    <script src="./js08_async_timer.js" async></script>
    <link rel="stylesheet" href="../style/common.css">
</head>
<body>
    <h1>异步：事件、定时器</h1>
    <p>定时器：setTimeout / setInterval</p>
    <p class="msg"></p>
    <p>
        <button>异步执行函数</button>
        <textarea name="" id="" cols="30" rows="10">
            点击“异步执行函数”后UI界面可以响应，不产生阻塞。
        </textarea>
    </p>
    <p class="timer"></p>
    <script>
        document.addEventListener("DOMContentLoaded",function(){
            let msg = document.querySelector(".msg");
            const btn=document.querySelector("button");
                btn.addEventListener("click",function(){
                    // 异步代码  
                    setTimeout(function(){
                        done(msg,100000000,0);
                        // msg.innerHTML += "操作完成";
                    },0);
                    //异步 “新增段落”不会受到上面的耗时操作的影响
                    let pElem=document.createElement("p");
                    pElem.textContent = "新增段落";
                    document.body.appendChild(pElem);
                });
                //显示事件的  事件器
                let dispTimer=document.querySelector(".timer");
                setInterval(function(){
                    dispTimer.textContent = new Date().toLocaleTimeString();
                },1000);

                setInterval((msg) => {//箭头函数
                    console.log(msg);
                },1000,"更多参数");
        })  

    </script>
</body>
</html>